package org.vaadin.activelink;

import org.vaadin.activelink.ActiveLink.LinkActivatedEvent;
import org.vaadin.activelink.ActiveLink.LinkActivatedListener;

import com.vaadin.server.ExternalResource;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

public class DemoRoot extends UI {

    static class Content extends VerticalLayout {

        Content() {

            ActiveLink link = new ActiveLink("Active link",
                    new ExternalResource("http://vaadin.com"));
            link.addListener(new LinkActivatedListener() {
                private static final long serialVersionUID = -7680743472997645381L;

                public void linkActivated(LinkActivatedEvent event) {
                    MouseEventDetails d = event.getMouseEventDetails();
                    String caption = "Link " + d.getButtonName() + "-clicked";
                    String msg = "Ctrl: " + d.isCtrlKey() + " Shift: "
                            + d.isShiftKey() + " Alt: " + d.isAltKey()
                            + " Meta: " + d.isMetaKey();
                    Notification.show(caption, msg, Type.WARNING_MESSAGE);
                    System.err.println(caption + " " + msg);

                }
            });
            addComponent(link);
        }
    }

    @Override
    protected void init(VaadinRequest request) {
        setContent(new Content());
    }
}
